package androidx.sqlite.db;

import android.app.ActivityManager;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import android.os.Bundle;
import android.os.CancellationSignal;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
public final class SupportSQLiteCompat {
	@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
	@RequiresApi(16)
	public static final class Api16Impl {
		@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
		public static void cancel(@NonNull CancellationSignal cancellationSignal) {
			cancellationSignal.cancel();
		}

		@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
		@NonNull
		public static CancellationSignal createCancellationSignal() {
			return new CancellationSignal();
		}

		@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
		public static boolean deleteDatabase(@NonNull File file) {
			return SQLiteDatabase.deleteDatabase(file);
		}

		@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
		@NonNull
		public static Cursor rawQueryWithFactory(@NonNull SQLiteDatabase sQLiteDatabase, @NonNull String sql, @NonNull String[] selectionArgs, @NonNull String editTable, @NonNull CancellationSignal cancellationSignal,
				@NonNull SQLiteDatabase.CursorFactory cursorFactory) {
			return sQLiteDatabase.rawQueryWithFactory(cursorFactory, sql, selectionArgs, editTable, cancellationSignal);
		}

		@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
		public static void setForeignKeyConstraintsEnabled(@NonNull SQLiteDatabase sQLiteDatabase, boolean enable) {
			sQLiteDatabase.setForeignKeyConstraintsEnabled(enable);
		}

		@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
		public static void disableWriteAheadLogging(@NonNull SQLiteDatabase sQLiteDatabase) {
			sQLiteDatabase.disableWriteAheadLogging();
		}

		@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
		public static boolean isWriteAheadLoggingEnabled(@NonNull SQLiteDatabase sQLiteDatabase) {
			return sQLiteDatabase.isWriteAheadLoggingEnabled();
		}

		@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
		public static void setWriteAheadLoggingEnabled(@NonNull SQLiteOpenHelper sQLiteOpenHelper, boolean enabled) {
			sQLiteOpenHelper.setWriteAheadLoggingEnabled(enabled);
		}
	}

	@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
	@RequiresApi(19)
	public static final class Api19Impl {
		@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
		@NonNull
		public static Uri getNotificationUri(@NonNull Cursor cursor) {
			return cursor.getNotificationUri();
		}

		@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
		public static boolean isLowRamDevice(@NonNull ActivityManager activityManager) {
			return activityManager.isLowRamDevice();
		}
	}

	@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
	@RequiresApi(21)
	public static final class Api21Impl {
		@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
		@NonNull
		public static File getNoBackupFilesDir(@NonNull Context context) {
			return context.getNoBackupFilesDir();
		}
	}

	@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
	@RequiresApi(23)
	public static final class Api23Impl {
		@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
		public static void setExtras(@NonNull Cursor cursor, @NonNull Bundle extras) {
			cursor.setExtras(extras);
		}
	}

	@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
	@RequiresApi(29)
	public static final class Api29Impl {
		@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
		public static void setNotificationUris(@NonNull Cursor cursor, @NonNull ContentResolver cr, @NonNull List<Uri> uris) {
			for(Uri uri:uris )
			cursor.setNotificationUri(cr, uri);

		}

		@RestrictTo({ androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP })
		@NonNull
		public static List<Uri> getNotificationUris(@NonNull Cursor cursor) {
			List<Uri> list =new ArrayList<Uri>();
			list.add(cursor.getNotificationUri());
			return list;
		}
	}
}